﻿#include <iostream>
using namespace std;


struct ListNode 
{
    int val;
    ListNode *next;
    ListNode() : val(0), next(nullptr) {}
    ListNode(int x) : val(x), next(nullptr) {}
    ListNode(int x, ListNode *next) : val(x), next(next) {}
};
 
class Solution
{
public:
    // 2. 两数相加
    ListNode* addTwoNumbers(ListNode* l1, ListNode* l2)
    {
        ListNode* newhead = new ListNode(-1);
        ListNode* tail = newhead;
        int t = 0;

        while (l1 || l2 || t)
        {
            if (l1)
            {
                t += l1->val;
                l1 = l1->next;
            }
            if (l2)
            {
                t += l2->val;
                l2 = l2->next;
            }
            tail->next = new ListNode(t % 10);
            tail = tail->next;
            t /= 10;
        }

        tail = newhead->next;
        delete newhead;
        return tail;
    }
};

int main()
{

    return 0;
}